//
//  mmjMeViewController.m
//  Social
//
//  Created by seirra on 2018/5/13.
//  Copyright © 2018年 mmj. All rights reserved.
//

#import "mmjMeViewController.h"
#import "mmjSettingViewController.h"
#import "mmjMeFootView.h"
@interface mmjMeViewController ()
@end

@implementation mmjMeViewController
-(instancetype)init{
    return [self initWithStyle:UITableViewStyleGrouped];
}
- (void)viewDidLoad {
    [super viewDidLoad];

    [self settable];
    [self setnavbar];
    
}
//设置tableview
-(void)settable{
    self.tableView.backgroundColor = mmjCommonBgColor;
    self.tableView.sectionHeaderHeight = 0;
    self.tableView.sectionFooterHeight = mmjMargin;
    self.tableView.contentInset = UIEdgeInsetsMake(mmjMargin - 35, 0, 0, 0);
    
    // 设置footer
    mmjMeFootView* footview = [[mmjMeFootView alloc] init];
    self.tableView.tableFooterView =footview ;
}
//导航栏
-(void)setnavbar{
    self.view.backgroundColor = mmjCommonBgColor;
    //标题
    self.navigationItem.title = @"我的";
    //右上角
    UIBarButtonItem* settingitem = [UIBarButtonItem itemwithimage:@"mine-setting-icon" highimage:@"mine-setting-icon-click" target:self action:@selector(settingClick)];
    
    UIBarButtonItem* moonitem = [UIBarButtonItem itemwithimage:@"mine-moon-icon" highimage:@"mine-moon-icon-click" target:self action:@selector(moonClick)];
    self.navigationItem.rightBarButtonItems = @[settingitem,moonitem];
}

#pragma mark 数据源方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    // 1.确定重用标示:
    static NSString *ID = @"me";
    
    // 2.从缓存池中取
    mmjMeCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    // 3.如果空就手动创建
    if (!cell) {
        cell = [[mmjMeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    // 4.设置数据
    if (indexPath.section == 0) {
        cell.textLabel.text = @"登录/注册";
        cell.imageView.image = [UIImage imageNamed:@"setup-head-default"];
    } else {
        cell.imageView.image = nil;
        cell.textLabel.text = @"离线下载";
        // 只要有其他cell设置过imageView.image, 其他不显示图片的cell都需要设置
        //imageView.image = nil
        
    }
    
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
    
}
-(void)settingClick{
    mmjSettingViewController* setting = [[mmjSettingViewController alloc]init];
    
    [self.navigationController pushViewController:setting animated:YES];
}
-(void)moonClick{
    
}
@end
